package javango.forms.fields;

import java.lang.annotation.Annotation;
import java.util.Map;

import javango.forms.ValidationException;
import javango.forms.widgets.Widget;

public interface Field {

	public static class Args {
		protected Class<? extends Field> fieldClass = CharField.class;
		public String name;
		public Widget widget;
		public boolean required = true;
	}
	
	// TODO should field allow cleaning of String's as well?
	// it is this way because servlets provide params as String[]...  just a thought to allow both.
	// String would just call clean(new String(){value}) anyway so not much code difference...
	// something to think about
	Object clean(String[] value, Map<String, String> errors) throws ValidationException;
	
	/**
	 * Return a cleaned up version of the initial value for this field.  
	 * If the value passed in is null the field should use its initial property. TODO reword this
	 * This is mainly here to support modelchoicefield and may not stay around. DDN
	 * 
	 * @param value
	 * @return
	 */
	Object cleanInitialValue(Object value);
	
	Field setName(String name);
	String getName();

	Widget getWidget();
	Field setWidget(Widget widget);
	Field setWidget(Class<? extends Widget> widgetClass);
	Class<? extends Widget> getWidgetClass();
	
	Widget getHiddenWidget();
	Field setHiddenWidget(Widget hiddenWidget);
	Field setHiddenWidget(Class<? extends Widget> widgetClass);
	Class<? extends Widget> getHiddenWidgetClass();
	
	boolean isRequired();
	Field setRequired(boolean required);

	Object getInitial();
	Field setInitial(Object initial);

	String getVerboseName();
	Field setVerboseName(String verboseName);
	
	String getHelpText();
	Field setHelpText(String helpText);	
		
	boolean isHidden();
	Field setHidden(boolean hidden);

	boolean isEditable();
	Field setEditable(boolean editable);

	boolean isAllowNull();
	Field setAllowNull(boolean allowNull);
	
	void handleAnnotation(Annotation annotation);
	
	Map<String, String> getWidgetAttrs();
}
